package asia.lxq.cic.dao;

import asia.lxq.cic.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Results({
            @Result(property = "commentId",id = true,column = "comment_id"),
            @Result(property = "subComment",many = @Many(select = "asia.lxq.cic.dao.CommentMapper.selectSubCommentByParentId"),
                    javaType = List.class,column = "comment_id")
    })
    @Select("select * from comment where comment_article_id=#{articleId} and comment_parent_id=0")
    List<Comment> selectCommentListByArticle(int articleId);

    @Select("select * from comment where comment_parent_id=#{parentId}")
    List<Comment> selectSubCommentByParentId(int parentId);
}
